package operation.modules.operation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import operation.modules.operation.dao.DatabaseManageDao;
import operation.modules.operation.dto.ColumnDTO;
import operation.modules.operation.entity.DbProjectEntity;
import operation.modules.operation.service.DatabaseManageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* 数据库管理 ServiceImpl
*/
@Service("databaseManageService")
public class DatabaseManageServiceImpl extends ServiceImpl<DatabaseManageDao, DbProjectEntity> implements DatabaseManageService {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 查询数据库所有表
     */
    public List<DbProjectEntity> queryAllDateBase () {
        List<DbProjectEntity> dataBaseList = baseMapper.queryAllDateBase();
        System.out.println("查询结果:" + dataBaseList);
        return dataBaseList;
    }

    /**
     * 查询指定表所有字段
     */
    public List<ColumnDTO> queryAllColumn(Map<String, Object> params) {
        QueryWrapper<ColumnDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_name", params.get("tableName").toString());
        queryWrapper.eq("table_schema", params.get("tableSchema").toString());
        List<ColumnDTO> columnDTOS = baseMapper.queryAllColumn(queryWrapper);
        System.out.println("查询结果:" + columnDTOS);
        return columnDTOS;
    }
}
